import request from "./useRequests";
import { userinfo } from '@/stores/counter'
import { ElMessage } from 'element-plus'

export default function enrollNotice() {
    const user = userinfo()
    async function enrollingNotice(noticeId: number, job: string, contactWay: string, topic: string, reason: string, more: string = '') {
        try {
            const res = await request.post('/user/enrollNotice', {
                "noticeId": noticeId,
                "job": job,
                "contactWay": contactWay,
                "topic": topic,
                "reason": reason,
                "more": more,
            })
            if (res.data.success) {
                ElMessage({
                    showClose: true,
                    message: '参与成功',
                    type: 'success',
                })
                return res.data.data
            }
            else {
                ElMessage({
                    showClose: true,
                    message: res.data.message,
                    type: 'error',
                })
                return null
            }
        } catch (err: any) {
            //alert(err)
        }
    }

    return {
        enrollingNotice
    }
}